package com.pro_test.servicebase.exceptionhandler;

import com.pro_test.commonutils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {
        //全局异常
        @ExceptionHandler(Exception.class)
        @ResponseBody
        public R error(Exception e){

            e.printStackTrace();
            return R.error().message("全局异常处理");
        }

        //自定义异常
        @ExceptionHandler(TestException.class)
        @ResponseBody
        public R error(TestException e){
            e.printStackTrace();
            return R.error().code(e.getCode()).message(e.getMsg());
        }

}
